package com.example.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.common.lang.Constant;
import com.example.service.*;
import com.example.shiro.AccountProfile;
import com.example.utils.RedisUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.ServletRequestUtils;

import javax.servlet.http.HttpServletRequest;

public class BaseController {

    @Autowired
    HttpServletRequest req;

    @Autowired
    RedisUtil redisUtil;

    @Autowired
    PostService postService;

    @Autowired
    CategoryService categoryService;

    @Autowired
    CommentService commentService;

    @Autowired
    UserService userService;

    @Autowired
    UserMessageService userMessageService;

    @Autowired
    UserCollectionService userCollectionService;

    @Autowired
    WsService wsService;

    @Autowired
    Constant constant;

    @Autowired
    ObjectMapper objectMapper;

    public Page getPage() {
        int pn =  ServletRequestUtils.getIntParameter(req, "pn", 1);
        int size =  ServletRequestUtils.getIntParameter(req, "size", 10);
        Page page = new Page(pn, size);
        return page;
    }

    public AccountProfile getProfile(){
        return (AccountProfile)SecurityUtils.getSubject().getPrincipal();
    }

    public long getProfileId(){
        return getProfile().getId();
    }

}
